/**
 * 
 */
package ro.dta.idbi.ui;

import java.util.Hashtable;
import java.util.Map;

import com.mxgraph.model.mxCell;
import com.mxgraph.model.mxGraphModel;
import com.mxgraph.util.mxConstants;
import com.mxgraph.view.mxGraph;
import com.mxgraph.view.mxStylesheet;

/**
 * Integration strategy graph, used to guide the user in choosing the
 * integration strategy
 * 
 * @author Tudor Dobrila
 * 
 */
public class StrategyGraph extends mxGraph {

	/**
	 * Strategy graph class constructor with empty model
	 */
	public StrategyGraph() {
		this(new mxGraphModel());
	}

	/**
	 * Strategy graph class constructor with defined initial model
	 * 
	 * @param model
	 *            Initial strategy model
	 */
	public StrategyGraph(final mxGraphModel model) {
		super(model);

		setCellsEditable(false);
		setCellsResizable(false);
		setCellsDeletable(false);
		setCellsCloneable(false);
		setAllowDanglingEdges(false);
		orderCells(false);
		setConnectableEdges(false);
		setDropEnabled(false);
		setMultigraph(false);

		// Create style sheets
		final mxStylesheet stylesheet = getStylesheet();
		this.createStylesheets(stylesheet);
	}

	@Override
	public boolean isCellEditable(final Object obj) {
		final mxCell cell = (mxCell) obj;
		boolean result = false;

		if (cell.isVertex() && cell.getStyle().equals("INTERMEDIATE")) {
			result = true;
		}

		return result;
	}

	/**
	 * Populate the style sheet with styles for this type of graph
	 * 
	 * @param styleSheet
	 *            Stylesheet to populate
	 */
	private void createStylesheets(final mxStylesheet styleSheet) {
		// Style for intermediate schemas
		final Map<String, Object> style = new Hashtable<String, Object>();
		style.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_RECTANGLE);
		style.put(mxConstants.STYLE_FONTSTYLE, mxConstants.FONT_ITALIC);
		style.put(mxConstants.STYLE_OPACITY, 50);
		style.put(mxConstants.STYLE_FONTCOLOR, "#000000");
		style.put(mxConstants.STYLE_FONTSIZE, 13);
		style.put(mxConstants.STYLE_FILLCOLOR, "#961919");
		styleSheet.putCellStyle("INTERMEDIATE", style);

	}
}
